<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tns="http://profiler.maschinenstuermer.com/trace">

	<xsl:output method="xml" indent="true" />

	<xsl:template match="/*">
		<xsl:element name="{name()}">
			<xsl:copy-of
				select="document('')/xsl:stylesheet/namespace::*[name() != 'xsl']" />
			<xsl:apply-templates select="@* | node()" />
		</xsl:element>
	</xsl:template>

	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="xs:complexType[@name='invocation']/xs:sequence/xs:choice">
		<xsl:copy>
			<xsl:attribute name="ecore:featureMap">child</xsl:attribute>
			<xsl:apply-templates select="node()|@*" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="xs:complexType[@name='invocation']/xs:sequence">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*" />
			<xs:element name="parentMetrics" type="tns:metrics"
				minOccurs="0" ecore:volatile="true" ecore:derived="true"
				ecore:changeable="false" ecore:unsettable="false" />
			<xs:element name="rootMetrics" type="tns:metrics"
				minOccurs="0" ecore:volatile="true" ecore:derived="true"
				ecore:changeable="false" ecore:unsettable="false" />

			<xs:element name="parentTimePercent" type="xs:int"
				minOccurs="0" ecore:volatile="true" ecore:derived="true"
				ecore:changeable="false" ecore:unsettable="false" />
			<xs:element name="rootTimePercent" type="xs:int"
				minOccurs="0" ecore:volatile="true" ecore:derived="true"
				ecore:changeable="false" ecore:unsettable="false" />

			<xs:element name="childTimeMs" type="xs:long" minOccurs="0"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />
			<xs:element name="selfTimeMs" type="xs:long" minOccurs="0"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="xs:complexType[@name='metrics']">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*" />

			<!-- emf enhancedment -->
			<xs:attribute name="avgTimeMs" use="required" type="xs:long"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />

			<xs:attribute name="totalTimeMs" use="required" type="xs:long"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />

			<xs:attribute name="maxTimeMs" use="required" type="xs:long"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />

			<xs:attribute name="minTimeMs" use="required" type="xs:long"
				ecore:volatile="true" ecore:derived="true" ecore:changeable="false"
				ecore:unsettable="false" />
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>
